
#property library
// indicator settings 
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_level1 50.0
#property indicator_level2 60.0
#property indicator_level3 70.0
#property indicator_level4 40.0
#property indicator_level5 30.0
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_style2 2
#property indicator_style3 2
#property indicator_levelcolor Red
#property indicator_levelstyle 0


double gd4C[];
double gd50[];
double gd54[];
double gd58[];
double gd5C[];
double gd60[];
double gd64[];
double gd68[];
extern int Smoothing = 5;
extern int TimeFrame = 0;
extern string ALERTS = "------------------------------------------------------";
extern bool CrossFiftyAlert = true;
extern bool CrossFiftyEmail = false;
extern bool CrossLineAlert = false;
extern bool CrossLineEmail = false;
extern bool BothAlert = false;
extern bool BothEmail = false;
extern string MESSAGES = "------------------------------------------------------";
extern string FiftyUpMessage = "QQE Crossed 50 Line UP !!!";
extern string FiftyDownMessage = "QQE Crossed 50 Line DOWN !!!";
extern string QQECrossUpMessage = "QQE Lines Crossed UP !!!";
extern string QQECrossDownMessage = "QQE Lines Crossed DOWN !!!";
extern string BothUpMessage = "QQE Lines Are Crossed and 50 Line Broken UP !!!";
extern string BothDownMessage = "QQE Lines Are Crossed and 50 Line Broken DOWN !!!";
extern string SOUNDS = "------------------------------------------------------";
extern string FiftyUpSound = "Koekoeksklok.wav";
extern string FiftyDownSound = "Koekoeksklok.wav";
extern string QQECrossUpSound = "Koekoeksklok.wav";
extern string QQECrossDownSound = "Koekoeksklok.wav";
extern string BothUpSound = "Koekoeksklok.wav";
extern string BothDownSound = "Koekoeksklok.wav";
extern string DOT_VISIBILITY = "------------------------------------------------------";
extern bool FiftyUpDot = true;
extern bool FiftyDownDot = true;
extern bool QQECrossUpDot = false;
extern bool QQECrossDownDot = false;
extern bool BothUpDot = false;
extern bool BothDownDot = false;
extern string DOT_COLORS = "------------------------------------------------------";
extern color FiftyUpColor = DodgerBlue;
extern color FiftyDownColor = Pink;
extern color QQECrossUpColor = Teal;
extern color QQECrossDownColor = Pink;
extern color BothUpColor = Blue;
extern color BothDownColor = Red;
extern string DOT_DISTANCE = "------------------------------------------------------";
extern int Distance = 30;
int gi150 = 0;
int gi154 = 0;
int gi158;


int init()
{
int li10, li1C;
string ls14, ls0;

/* !!! block begin */
IndicatorBuffers( 8 );
SetIndexBuffer( 0, gd50 );
SetIndexBuffer( 1, gd54 );
SetIndexBuffer( 2, gd58 );
SetIndexBuffer( 3, gd4C );
SetIndexBuffer( 4, gd5C );
SetIndexBuffer( 5, gd60 );
SetIndexBuffer( 6, gd64 );
SetIndexBuffer( 7, gd68 );
li10 = TimeFrame;
if (li10 != 1) {
 if (li10 != 5) {
   if (li10 != 15) {
     if (li10 != 30) {
       if (li10 != 60) {
         if (li10 != 240) {
           if (li10 != 1440) {
             if (li10 != 10080) {
               if (li10 != 43200) {
                 ls14 = "Current Timeframe";
        }
        else {
                 ls14 = "Period_MN1";
        }

       }
       else {
               ls14 = "Period_W1";
       }

      }
      else {
             ls14 = "Period_D1";
      }

     }
     else {
           ls14 = "Period_H4";
     }

    }
    else {
         ls14 = "Period_H1";
    }

   }
   else {
       ls14 = "Period_M30";
   }

  }
  else {
     ls14 = "Period_M15";
  }

 }
 else {
   ls14 = "Period_M5";
 }

}
else {
 ls14 = "Period_M1";
}

MathSrand( TimeLocal() );
IndicatorShortName( ("QQE " + ls14) );
return( 0 );
}

int deinit()
{
int li0;
string ls4;

/* !!! block begin */
li0 = 32768;
while (li0 > 0) {
 ObjectDelete( ("QQE-" + li0) );
 li0 = li0-1;
}

return( 0 );
}

int start()
{
int li0, li18, liC, la14[], li4, li8, li38, li48, li50;
double ld70, ld60;
string ls40, ls30, ls78;

/* !!! block begin */
li0 = IndicatorCounted();
if (li0 < 0) return( -1 );
if (li0 > 0){}
li18 = (Bars - li0-1);
liC = Smoothing;
ArrayCopySeries( la14, MODE_TIME, Symbol(), TimeFrame );
li4 = 0;
li8 = 0;
while (li4 < li18) {
 if (Time[li4] < la14[li8]) li8 = li8+1;
 gd4C[li4] =iRSI( 0, TimeFrame, 14, 0, li8 );
 li4 = li4+1;
}

li4 = 0;
li8 = 0;
while (li4 < li18) {
 if (Time[li4] < la14[li8]) li8 = li8+1;
 gd50[li8] =iMAOnArray( gd4C, 0, Smoothing, 0, MODE_EMA, li8 );
 li4 = li4+1;
}

li4 = 0;
while (li4 < li18) {
 gd60[li4] =(MathMax( gd50[(li4 + 1)], gd50[li4] ) - MathMin( gd50[(li4 + 1)], gd50[li4] ));
 li4 = li4+1;
}

li4 = 0;
while (li4 < li18) {
 gd5C[li4] =iMAOnArray( gd60, 0, 27, 0, MODE_EMA, li4 );
 li4 = li4+1;
}

li4 = 0;
while (li4 < li18) {
 gd64[li4] =(iMAOnArray( gd5C, 0, 27, 0, MODE_EMA, li4 ) * 2.618);
 li4 = li4+1;
}

li4 = li18;
while (li4 >= 0) {
 if (gd50[li4] == gd54[(li4 + 1)]) {
   gd54[li4] =gd50[li4];
 }
 else {
   if (((gd50[(li4 + 1)] < gd54[(li4 + 1)]) && (gd50[li4] < gd54[(li4 + 1)])) == 1) {
     gd54[li4] =MathMin( gd54[(li4 + 1)], (gd50[li4] + gd64[li4]) );
  }
  else {
     if (((gd50[(li4 + 1)] > gd54[(li4 + 1)]) && (gd50[li4] > gd54[(li4 + 1)])) == 1) {
       gd54[li4] =MathMax( gd54[(li4 + 1)], (gd50[li4] - gd64[li4]) );
   }
   else {
       if (gd50[li4] > gd54[(li4 + 1)]) {
         gd54[li4] =(gd50[li4] - gd64[li4]);
    }
    else {
         gd54[li4] =(gd50[li4] + gd64[li4]);
    }

   }

  }

 }

 li4 = li4-1;
}

li4 = 0;
while (li4 < li18) {
 gd68[li4] =(iMAOnArray( gd5C, 0, 27, 0, MODE_EMA, li4 ) * 4.236);
 li4 = li4+1;
}

li4 = li18;
while (li4 >= 0) {
 if (gd50[li4] == gd58[(li4 + 1)]) {
   gd58[li4] =gd50[li4];
 }
 else {
   if (((gd50[(li4 + 1)] < gd58[(li4 + 1)]) && (gd50[li4] < gd58[(li4 + 1)])) == 1) {
     gd58[li4] =MathMin( gd58[(li4 + 1)], (gd50[li4] + gd68[li4]) );
  }
  else {
     if (((gd50[(li4 + 1)] > gd58[(li4 + 1)]) && (gd50[li4] > gd58[(li4 + 1)])) == 1) {
       gd58[li4] =MathMax( gd58[(li4 + 1)], (gd50[li4] - gd68[li4]) );
   }
   else {
       if (gd50[li4] > gd58[(li4 + 1)]) {
         gd58[li4] =(gd50[li4] - gd68[li4]);
    }
    else {
         gd58[li4] =(gd50[li4] + gd68[li4]);
    }

   }

  }

 }

 li4 = li4-1;
}

if (gi158 == Time[0]) return( 0 );
li4 = (li18 - 1);
while (li4 >= 0) {
 if ((((gd50[(li4 + 1)] > 50.0) && (gd50[(li4 + 2)] <= 50.0)) && FiftyUpDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (Low[li4] - (Distance * Point)) );
   ObjectSet( ls30, 6, FiftyUpColor );
   ObjectSet( ls30, 14, 108 );
 }

 if ((((gd50[(li4 + 1)] < 50.0) && (gd50[(li4 + 2)] >= 50.0)) && FiftyDownDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (High[li4] + (Distance * Point)) );
   ObjectSet( ls30, 6, FiftyDownColor );
   ObjectSet( ls30, 14, 108 );
 }

 if ((((gd50[(li4 + 1)] > gd58[(li4 + 1)]) && (gd50[(li4 + 2)] < gd58[(li4 + 2)])) && QQECrossUpDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (Low[li4] - (Distance * Point)) );
   ObjectSet( ls30, 6, QQECrossUpColor );
   ObjectSet( ls30, 14, 108 );
 }

 if ((((gd50[(li4 + 1)] < gd58[(li4 + 1)]) && (gd50[(li4 + 2)] > gd58[(li4 + 2)])) && QQECrossDownDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (High[li4] + (Distance * Point)) );
   ObjectSet( ls30, 6, QQECrossDownColor );
   ObjectSet( ls30, 14, 108 );
 }

 if (((((gd50[(li4 + 1)] > gd58[(li4 + 1)]) && ((gd50[(li4 + 1)] > 50.0) && (gd50[(li4 + 2)] <= 50.0))) || (((gd50[(li4 + 1)] > gd58[(li4 + 1)]) && (gd50[(li4 + 2)] < gd58[(li4 + 2)])) && (gd50[(li4 + 1)] > 50.0))) && BothUpDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (Low[li4] - (Distance * Point)) );
   ObjectSet( ls30, 6, BothUpColor );
   ObjectSet( ls30, 14, 108 );
 }

 if (((((gd50[(li4 + 1)] < gd58[(li4 + 1)]) && ((gd50[(li4 + 1)] < 50.0) && (gd50[(li4 + 2)] >= 50.0))) || (((gd50[(li4 + 1)] < gd58[(li4 + 1)]) && (gd50[(li4 + 2)] > gd58[(li4 + 2)])) && (gd50[(li4 + 1)] < 50.0))) && BothDownDot) == 1)
 {
   ls30 = ("QQE-" + (MathRand() + 1));
   ObjectCreate( ls30, OBJ_ARROW, 0, Time[li4], (High[li4] + (Distance * Point)) );
   ObjectSet( ls30, 6, BothDownColor );
   ObjectSet( ls30, 14, 108 );
 }

 li4 = li4-1;
}

if (((gd50[1] > 50.0) && (gd50[2] <= 50.0)) == 1)
{
  if (CrossFiftyAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", FiftyUpMessage, "   @   ", Bid, " + ", (Ask - Bid), " = ", Ask );
    Comment( Symbol(), " ", Period(), "M   ", FiftyUpMessage, "   @   ", Bid, " + ", (Ask - Bid), " = ", Ask, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( FiftyUpSound );
  }

  if (CrossFiftyEmail == 1) SendMail( (FiftyUpMessage + Symbol()), " !!! " );
}

if (((gd50[1] < 50.0) && (gd50[2] >= 50.0)) == 1)
{
  if (CrossFiftyAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", FiftyDownMessage, "   @   ", Bid );
    Comment( Symbol(), " ", Period(), "M   ", FiftyDownMessage, "   @   ", Bid, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( FiftyDownSound );
  }

  if (CrossFiftyEmail == 1) SendMail( (FiftyDownMessage + Symbol()), " !!! " );
}

if (((gd50[1] > gd58[1]) && (gd50[2] < gd58[2])) == 1)
{
  if (CrossLineAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", QQECrossUpMessage, "   @   ", Bid, " + ", (Ask - Bid), " = ", Ask );
    Comment( Symbol(), " ", Period(), "M   ", QQECrossUpMessage, "   @   ", Bid, " + ", (Ask - Bid), " = ", Ask, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( QQECrossUpSound );
  }

  if (CrossLineEmail == 1) SendMail( (QQECrossUpMessage + Symbol()), " !!! " );
}

if (((gd50[1] < gd58[1]) && (gd50[2] > gd58[2])) == 1)
{
  if (CrossLineAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", QQECrossDownMessage, "   @   ", Bid );
    Comment( Symbol(), " ", Period(), "M   ", QQECrossDownMessage, "   @   ", Bid, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( QQECrossDownSound );
  }

  if (CrossLineEmail == 1) SendMail( (QQECrossDownMessage + Symbol()), " !!! " );
}

if (((((gd50[(li4 + 1)] > gd58[1]) && ((gd50[1] > 50.0) && (gd50[2] <= 50.0))) || (((gd50[1] > gd58[(li4 + 1)]) && (gd50[2] < gd58[2])) && (gd50[1] > 50.0))) && BothUpDot) == 1)
{
  if (BothAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", BothUpMessage, "   @   ", Bid );
    Comment( Symbol(), " ", Period(), "M   ", BothUpMessage, "   @   ", Bid, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( BothUpSound );
  }

  if (BothEmail == 1) SendMail( (BothUpMessage + Symbol()), " !!! " );
}

if (((((gd50[1] < gd58[1]) && ((gd50[1] < 50.0) && (gd50[2] >= 50.0))) || (((gd50[1] < gd58[1]) && (gd50[2] > gd58[2])) && (gd50[1] < 50.0))) && BothDownDot) == 1)
{
  if (BothAlert == 1)
  {
    Print( Symbol(), " ", Period(), "M   ", BothDownMessage, "   @   ", Bid );
    Comment( Symbol(), " ", Period(), "M   ", BothDownMessage, "   @   ", Bid, "\n", "TIME ON ALERT IS : ", TimeToStr( TimeCurrent() ) );
    PlaySound( BothDownSound );
  }

  if (BothEmail == 1) SendMail( (BothDownMessage + Symbol()), " !!! " );
}

gi158 = Time[0];
return( 0 );
}


